/*
 * @Author: 'Huaiantree' '2577850557@qq.com'
 * @Date: 2025-09-18 22:23:04
 * @LastEditors: 'Huaiantree' '2577850557@qq.com'
 * @LastEditTime: 2025-10-16 01:22:11
 * @FilePath: \easyTool-client\src\api\companies.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

import http from '../utils/http'

export interface ApiResponse<T = any> {
  code: number
  message: string
  data?: T
}

    // 获取公司列表
export const getCompanies = () => {

  // console.log("======="+http.get<ApiResponse>('/companies'))
  return http.get<ApiResponse>('/companies')
}
// 获取赛事数据
export interface MainTableParams {
  page?: number
  per_page?: number
  cid?: string | number
  keyword?: string
  score?: string
  morning_session?: string
  closing_session?: string
  midfield?: string
  big_small_plate?: string
  mid_big_small_plate?: string
}
export const getMatchData = (body?: MainTableParams) => {
  return http.post<ApiResponse>('/mainTable/search', body )
}

// 获取赛事详情表（返回 HTML 表格内容）
export const getDetailTable = (mid: string | number) => {
  return http.get(`/detailTable/${mid}`, { responseType: 'text' })
}

// 获取赛事详情表2（返回 HTML 表格内容）
export const getDetailTable2 = (mid: string | number) => {
  return http.get(`/detailTable2/${mid}`, { responseType: 'text' })
}

// 开始爬取（根据公司 cid 和赛事 pid）
export interface StartClimbRequest {
  cid: string | number
  pid: string | number
  t1?: string
  t2?: string
  firstscore?: string
}
export const startClimb = (data: StartClimbRequest) => {
  // 设置为10分钟超时，适应长时间爬取
  return http.post<ApiResponse>('/mainTable/climbpcid', data, { timeout: 600000 })
}



// 指数（初盘/即时）- 可能需要同时传递 cid 和 pid
export interface ExponentResponse {
  cid: string
  pid: string
  dopen: string
  dopen2: string
  id?: number
  mteam: string
  mteam2: string
  vteam: string
  vteam2: string
  created_at?: string
}
export const getExponent = (cid: string | number, pid?: string | number) => {
  const params = pid ? `?cid=${cid}&pid=${pid}` : `?cid=${cid}`
  return http.get<ExponentResponse>(`/exponent${params}`)
}

// 总计统计（主/和/客 与 "2" 组）
export interface MainTableCountResponse {
  chang2_count: number
  chang_count: number
  ke2_count: number
  ke_count: number
  main2_count: number
  main_count: number
  ping2_count: number
  ping_count: number
}
export const getMainTableCount = (cid: string | number, pid?: string | number) => {
  const params = pid ? `?cid=${cid}&pid=${pid}` : `?cid=${cid}`
  return http.get<MainTableCountResponse>(`/mainTable/count${params}`)
}

// 刷新赛事数据
export interface RefreshEventsRequest {
  date: string
}
export const refreshEvents = (data: RefreshEventsRequest) => {
  return http.post<ApiResponse>('/mainTable/event', data)
}
